package com.sz.stock.controller;

import com.sz.stock.model.POS;
import com.sz.stock.model.PageBean;
import com.sz.stock.model.ResultBean;
import com.sz.stock.service.IPosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pos")
public class PosController {
    @Autowired
    private IPosService posService;

    /**
     * 增
     * @param addPos
     * @return
     */
    @RequestMapping("/add")
    ResultBean add(@RequestBody(required = false)POS addPos){
        int i = posService.posAdd(addPos);
        if(i>0){
            return new ResultBean(0,"添加成功!",i);
        }else{
            return new ResultBean(-1,"添加失败!",i);
        }
    }

    /**
     * 删、改
     * @param updateOrDeletePos
     * @return
     */
    @RequestMapping("/updateOrDelete")
    ResultBean updateOrDelete(@RequestBody(required = false)POS updateOrDeletePos){
        int i = posService.posUpdate(updateOrDeletePos);
        if(i>0){
            return new ResultBean(0,"更新成功!",i);
        }else{
            return new ResultBean(-1,"更新失败!",i);
        }
    }

    /**
     * 查
     * @param userid
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @RequestMapping("/pageSearch")
    ResultBean pageSearch(Integer userid, Integer pageIndex, Integer pageSize, String searchCode){
        PageBean<POS> posPageBean = posService.allPos2(userid, pageIndex, pageSize, searchCode);
        return new ResultBean(0,"查询成功!",posPageBean);
    }
}
